import { isH5, isMpWeixin } from '@/env'
import { getScaleValue, mapPageUrl } from '@/common/utils/utils'

export const CommonMixin = {
  data () {
    return {}
  },
  computed: {
    isH5 () {
      return isH5()
    },
    // 按需添加platform判断
    isMpWeixin () {
      return isMpWeixin()
    },
    animScale () {
      return getScaleValue()
    },
    isPc () {
      return this.isH5 ? window.__TYPE === 'pc' : false
    },
    isInner () {
      return this.isH5 ? window.__TYPE === 'mh' : false
    }
  },
  methods: {
    navigateTo (rawUrl) {
      const arr = rawUrl.split('/')
      const path = arr[arr.length - 1]
      if (isH5()) {
        // TODO: 'index' is your first page
        this.$router.push({ type: 'navigateTo', path: `${path === 'index' ? '/' : path}`, replace: true })
        return
      }
      uni.navigateTo({
        url: mapPageUrl(rawUrl)
      })
    },
    navigateBack () {
      if (isH5()) {
        this.$router.go(-1)
        return
      }
      uni.navigateBack({
        delta: 1
      })
    },
    judgePage () {
      if (this.$options.template || this.$options.render) {
        return false
      } else {
        return true
      }
    }
  }
}
